package com.zonski.jbots.game.resources;

import com.zonski.jbots.engine.UsableResource;
import com.zonski.jbots.engine.Resource;
import com.zonski.jbots.engine.Engine;
import com.zonski.jbots.engine.QuickVector;

import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: Chris Glover
 * Date: 28/04/2004
 * Time: 08:49:01
 * To change this template use Options | File Templates.
 */
public class CompositeEggMaker extends EggMaker
{
    private QuickVector levels;

    public CompositeEggMaker()
    {
        this.levels = new QuickVector(5);
        this.minCharge = Integer.MAX_VALUE;
        this.maxCharge = Integer.MIN_VALUE;
    }

    public void addEgg(int minCharge, int maxCharge, String toCreate)
    {
        this.levels.addElement(new EggInfo(minCharge, maxCharge, toCreate));
        this.minCharge = Math.min(minCharge, this.minCharge);
        this.maxCharge = Math.max(maxCharge, this.maxCharge);
    }

    public Resource copy()
    {
        CompositeEggMaker eggMaker = new CompositeEggMaker();
        eggMaker.levels = this.levels;
        eggMaker.maxCharge = this.maxCharge;
        eggMaker.minCharge = this.minCharge;
        return eggMaker;
    }

    public String getToCreate()
    {
        int charge = this.getCharge();
        String toCreate = null;
        for(int i=0; i<this.levels.size(); i++)
        {
            EggInfo egg = (EggInfo)this.levels.elementAt(i);
            if(egg.minCharge <= charge && egg.maxCharge >= charge)
            {
                toCreate = egg.toCreate;
            }
        }
        return toCreate;
    }

    protected int getMaxCharge(String toCreate)
    {
        for(int i=0; i<this.levels.size(); i++)
        {
            EggInfo egg = (EggInfo)this.levels.elementAt(i);
            if(egg.toCreate.equals(toCreate))
            {
                return egg.maxCharge;
            }
        }
        return 0;
    }

    private class EggInfo
    {
        public int minCharge;
        public int maxCharge;
        public String toCreate;

        public EggInfo(int minCharge, int maxCharge, String toCreate)
        {
            this.minCharge = minCharge;
            this.maxCharge = maxCharge;
            this.toCreate = toCreate;
        }
    }
}
